<template>
    <div class="template-list">
        <div class="template-item" v-for="item in props.list" :key="item.id">
            <div class="template-content">
                <div class="template-img">
                    <NuxtImg :alt="item.name" :title="item.name" class="cover-img" :src="item.file +
                        '?x-oss-process=image/resize,w_864/watermark,image_' +
                        toBase64(
                            'water/logo_white.png?x-oss-process=image/resize,P_30'
                        ) +
                        ',g_center,t_60/format,webp'
                        " loading="lazy" />
                    <!-- <img class="preview" :src="`${_oss_}images/template/preview.png`" alt="北京华锐云空间" /> -->
                    <div class="preview">
                        <div class="btn btn-plain" @click="onPreview(item)">点击预览</div>

                        <el-button class="btn-jump" color="#fff" type="primary" :disabled="!item.url"
                            @click.stop="item.url ? onMakeModel(item) : ''">
                            <!-- {{ item.is_buy == 1 ? "开始创作" : "免费制作" }} -->
                            制作同款
                        </el-button>

                        <el-button :type="item.is_buy == 1 ? 'warning' : 'primary'" @click.stop="onBuyModel(item)"
                            onfocus="this.blur()" v-if="IsNeedPay(item)" :disabled="!item.url">
                            {{ item.is_buy == 1 ? "可升级" : "购买" }}
                        </el-button>
                    </div>
                    <img class="free-icon" v-if="item.templatestype_code == 'courseware'"
                        :src="`${_oss_}images/free-icon.png`" />

                    <div class="review-num">
                        <img :src="`${_oss_}images/works/icon-view-white.png`" alt="北京华锐云空间" />
                        <span>{{ item.page_view || 0 }}</span>
                    </div>
                </div>

                <div class="template-info">
                    <div class="template-top">
                        <div class="template-name" :title="item.name">
                            {{ item.name }}
                        </div>

                        <img class="share-btn" :src="`${_oss_}images/template/icon-share.png`" @click="onShare(item)">
                    </div>

                    <div class="template-footer">
                        <div class="icon-group">
                            <template v-if="item.templatestype_code == 'template'">
                                <div class="icon-item">
                                    <img :src="`${_oss_}images/template/icon-area.svg`" />
                                    {{ item.area }}m²
                                </div>
                            </template>

                            <div class="sales-volume" v-if="IsNeedPay(item)">
                                已销售：{{ item.sales || 0 }}
                            </div>
                        </div>

                        <div class="template-desc">
                            {{ item.description }}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script setup>
import { onMakeModel, onPreview, IsNeedPay, onBuyModel, onShare } from ".";
const props = defineProps({
    list: {
        type: Array,
        default: () => [],
    },
    type: {
        type: [Number, String],
        default: 0,
    },
});
</script>
<style lang="scss" scoped>
.template-list {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 16px;

    .template-item {
        position: relative;
        width: 288px;
        height: 384px;

        &:hover {
            z-index: 1;

            .template-content {
                position: absolute;
                left: 0;
                top: 0;
                height: auto;
                box-shadow: 0px 0px 8px 3px rgba(0, 0, 0, 0.11);
                transition: box-shadow 0.5s;

                .template-desc {
                    -webkit-line-clamp: none !important;
                }
            }
        }

        .template-content {
            height: 100%;
            background-color: #fff;
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 0px 0px 6px 0px rgba(0, 0, 0, 0.05);
            transition: box-shadow 0.5s;

            .free,
            .price {
                position: absolute;
                left: 0;
                top: 0;
                display: inline-flex;
                align-items: center;
                justify-content: center;
                border-radius: 10px 0 10px 0;
                font-size: 14px;
                color: #fff;
            }

            .price {
                width: 90px;
                height: 26px;
                background: linear-gradient(-90deg, #ff3527, #ff8846);
            }

            .free {
                width: 46px;
                height: 26px;
                background: #999999;
            }

            &:nth-of-type(4n) {
                margin-right: 0;
            }

            .top {
                position: absolute;
                top: 11px;
                right: 16px;
                font-size: 14px;
                color: #fff;
                z-index: 9;
            }

            .template-img {
                position: relative;
                width: 288px;
                height: 238px;
                overflow: hidden;
                cursor: pointer;

                &:hover {
                    // .cover-img {
                    //     transform: scale(1.4);
                    // }

                    .preview {
                        opacity: 1;
                    }
                }

                .free-icon {
                    position: absolute;
                    top: 0;
                    right: 0;
                }

                .cover-img {
                    width: 100%;
                    height: 100%;
                    object-fit: cover;
                    transition: all 0.4s linear;
                }

                .preview {
                    display: flex;
                    flex-direction: column;
                    align-items: center;
                    justify-content: center;

                    width: 100%;
                    height: 100%;
                    background-color: rgba(0, 0, 0, 0.3);
                    opacity: 0;
                    position: absolute;
                    left: 0;
                    top: 0;
                    transition: all 0.4s linear;
                    z-index: 9;

                    :deep(.el-button) {
                        width: 88px;
                    }

                    :deep(.el-button + .el-button) {
                        margin-left: 0;
                        margin-top: 12px;
                    }

                    .btn-plain {
                        display: flex;
                        align-items: center;
                        justify-content: center;

                        width: 88px;
                        height: 32px;
                        border-radius: 4px;
                        border: 1px solid #FFFFFF;
                        font-size: 14px;
                        color: #FEFEFE;
                        margin-bottom: 12px;
                    }
                }

                .review-num {
                    position: absolute;
                    left: 7px;
                    top: 8px;
                    display: flex;
                    align-items: center;
                    color: #fff;
                    font-size: 14px;
                    background-color: rgba(0, 0, 0, 0.3);
                    padding: 6px 7px;
                    border-radius: 4px;

                    img {
                        margin-right: 5px;
                    }
                }
            }

            .template-info {
                padding: 0 12px 8px;

                .template-top {
                    display: flex;
                    align-items: center;
                    height: 49px;
                    border-bottom: 1px solid #DDDDDD;

                    .template-name {
                        font-size: 18px;
                        width: 180px;
                        font-weight: 500;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        white-space: nowrap;
                    }

                    .share-btn {
                        width: 20px;
                        margin-left: auto;
                        cursor: pointer;
                    }

                    .el-button {
                        margin-top: 5px;
                        margin-left: auto;

                        &:first-of-type {
                            margin-top: 0px;
                        }
                    }
                }

                .el-button {
                    padding: 0 !important;
                    width: 80px;
                    height: 30px;
                }
            }

            .template-title {
                font-size: 18px;
                color: #333;
            }

            .template-footer {
                margin-top: 12px;

                .icon-group {
                    width: 100%;
                    display: flex;
                    align-items: center;
                    justify-content: space-between;
                    color: #999;
                    font-size: 14px;
                    height: 16px;

                    .icon-item {
                        display: inline-flex;
                        align-items: center;
                        margin-right: 9px;

                        img {
                            width: 12px;
                            margin-right: 3px;
                        }
                    }

                    .sales-volume {
                        font-size: 12px;
                        color: #999;
                    }
                }

                .template-desc {
                    font-size: 14px;
                    color: #666666;
                    margin-top: 13px;
                    line-height: 24px;
                    min-height: 48px;

                    display: -webkit-box;
                    -webkit-box-orient: vertical;
                    -webkit-line-clamp: 2;
                    overflow: hidden;
                }
            }

            .template-price {
                font-size: 14px;
                color: #666666;
                margin-right: auto;
            }
        }

    }
}
</style>
